{include file="public/top" /}

<body>
<div class="x-body">
    <form class="layui-form">
        <div class="layui-form-item">
            <label class="layui-form-label">
                <span class="x-red">*</span>名称
            </label>
            <div class="layui-input-block">
                <input type="text" id="name" name="name" required="" lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
            <br>
            <label class="layui-form-label">
                <span class="x-red">*</span>手机
            </label>
            <div class="layui-input-block">
                <input type="text" id="mobile" name="mobile" required="" lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
            <br>
            <label class="layui-form-label">
                <span class="x-red">*</span>邮箱
            </label>
            <div class="layui-input-block">
                <input type="text" id="email" name="email" required="" lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
            <br>
            <label class="layui-form-label">
                <span class="x-red">*</span>传真
            </label>
            <div class="layui-input-block">
                <input type="text" id="fax" name="fax" required="" lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
            <br>
            <label class="layui-form-label">
                <span class="x-red">*</span>部门
            </label>
            <div class="layui-input-block">
                <input type="text" id="branch" name="branch" required="" lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
            <br>
        </div>

        <div class="layui-form-item" style="margin-left: 100px">
            <button type="button"  class="layui-btn layui-btn-normal" lay-filter="add" lay-submit="">提交</button>
        </div>
    </form>
</div>
<script>

    var addurl = '/admin/Salesman/add';
    var imgupUrl = '/admin/index/imgUp';
    var zipupUrl = '/admin/index/zipUp';
    var ue = UE.getEditor('editor');
    //编辑器
    layui.use(['form','layer'], function(){
        $ = layui.jquery;
        var form = layui.form
            ,layer = layui.layer;

        //自定义验证规则
        form.verify({
            pass: [/(.+){6,12}$/, '密码必须6到12位']
            ,repass: function(value){
                if($('#L_pass').val()!=$('#L_repass').val()){
                    return '两次密码不一致';
                }
            }
        });
        //监听提交
        form.on('submit(add)', function(data){
            $.post(addurl, data.field,function(res) {
                var success = JSON.parse(res);
                if(success.code===200){
                    layer.msg(success.msg, {
                        time: 1000, //不自动关闭
                        icon:6,
                        end:function () {
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        }
                    });
                    return false;
                }else {
                    layer.msg(success.msg)
                }


            });

        });
    });
    layui.use('upload', function(){
        var upload = layui.upload;
        //执行实例
        var uploadInst = upload.render({
            elem: '#test1' //绑定元素
            ,url: imgupUrl //上传接口
            ,done: function(res){
                var  option = '<img style="height: 80px;width: 120px;margin: 0 10px 0 0;cursor:pointer;" src="'+res.data+'">';
                $('#imgg1').html(option);
                var addBox = '<input type="hidden" name="img_url" value="'+res.data+'">';
                document.getElementById('t1').innerHTML += addBox;
            }
            ,error: function(){
                //请求异常回调
            }
        });
        var uploadInst = upload.render({
            elem: '#test2' //绑定元素
            ,url: zipupUrl,//上传接口
            accept:'file'
            ,done: function(res){
                var  option = '<span>上传成功：'+ res.data +'</span>';
                $('#zip').html(option);
                var addBox = '<input type="hidden" name="zip_url" value="'+res.data+'">';
                document.getElementById('t2').innerHTML += addBox;
            }
            ,error: function(){
                //请求异常回调
            }
        });
    });
</script>


</body>

</html>